/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mscs.data;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;
import mscs.data.pojo.Goods;

/**
 *
 * @author Usbuild
 */
public class GoodsUtil implements IDataView,IDataSearch {

    public List toStringArray(Goods goods) {
        Vector<String> list = new Vector<String>();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        list.add(((Integer)goods.getId()).toString());
        list.add(((Integer)goods.getNum()).toString());
        list.add(goods.getDesc());
        list.add(((Double)goods.getSalPrice()).toString());
        list.add(sdf.format(goods.getProDate()));
        list.add(sdf.format(goods.getDesDate()));
        list.add(sdf.format(goods.getEntDate()));
        list.add(((Double)goods.getBasPrice()).toString());
        return list;
    }
       
    public List find(List list, Object obj) {
        Vector<Goods> reList = new Vector<Goods>();
        Vector<Goods> seList;
        if (list == null)
            seList = new Vector<Goods>();
        else
            seList = (Vector<Goods>)list;
        for(Goods goods : seList)
            if (goods.getId() == ((Goods)obj).getId() )
                reList.add(goods);
        return reList;
    }

    public Vector<Vector<String>> toDataTable(List list) {
        Vector<Goods> seList = (Vector<Goods>)list;
        Vector<Vector<String>> reList = new Vector<Vector<String>>();
        for (Goods goods : seList)
        {
            reList.add((Vector<String>)toStringArray(goods));
        }
        return reList;
    }
    
}
